<div class="tab-pane fade" id="downloadTab">
	<div class="span12">
	<div class="box gradient">
	 
		<div class="title">
				<h4>
				<span>Product Download </span> <span class="box-form right"> </span>
				
				<span class="box-form right productDownload_bar"><a href="#" class="btn btn-mini addProductDownload">Add Product Download</a></span>
 				</h4>
 				<a href="#" class="minimize"> </a>
			</div>
		 <div class="content scrollable clearfix">
		<table class="table table-bordered table-vertical-centre productDownloadTable">
			<thead>
				<tr>
					<th><a class="select_all"><span class="icomoon-icon-checkmark-2"></span></a></th>
<th>Name </th>
<th>Image </th>
<th>Order Rank </th>
<th>Date </th>
<th>Attachment	Url</th>
<th>Link</th>
<th>Category </th>

 					<th>Action</th>
				</tr>
			</thead>
		</table>
		</div>
	 
</div>
 </div>
</div>




<script>
 
 

$(document).ready(function(){
	$("a[href='#downloadTab']").click(function (e) {
		   if (!$(this).hasClass("inited")){
			   $(this).addClass("inited");
			   
			   setTimeout(function(){
				   
					
					var del = {
							id : 'productDownloadDel',
							text  : 'Del',
							domain : "Product Download",
							operation : "Del",
							url : "${ctx}/admin/product-download/del/",
							selector : ".productDownload_bar",
							selects  : $('.productDownloadTable'),
					  
					};
					johnny.tableBtn(del);
					
				 	
					
					$('.addProductDownload').click(function(){
					$("#productDownloadDiv").find("div.modal-body").find("input,select,textarea,checkbox").not("[name=action],[type=hidden]").not("[type=radio]").each(function(step,value){
					 									$(value).val("");
					 							});
					
					
					
					 $("#productDownloadDiv input[name='action']").val("${ctx}/admin/product-download/create/");
				 	 $("#productDownloadDiv").modal('show');
				  });
					
					  $(document).delegate('.productDownloadTable .icomoon-icon-pencil', 'click', function(event) {
						  
						  	var id = $(this).parent().attr("dataid");
							$.ajax({
								url : "${ctx}/admin/product-download/"+id+"/edit/",
								type : "GET",
								dataType : "json",
								success : function(data){		
									if(data && data.state && (data.state.indexOf("ERROR") != -1)){
										johnny.error(data.message);
										return;
									}else{
											var entity = data.entity;
											
											
											
				 							$("#productDownloadDiv").find("div.modal-body").find("input,select,textarea,checkbox").not("[name=action],[type=hidden]").each(function(step,value){
													var name = $(value).attr("name");
													if ($(value).is(':radio')) {
														if (""+entity[name] ===""+$(value).val()){
				  												$(value).attr("checked","checked");
				   											}else{
				   												$(value).removeAttr("checked");
				 																			
				 											}
														
													}else{
				 									if (entity[name]|| entity[name]===0){
														$(value).val(entity[name]);
				 										$(value).uniform();
				 									}else if (name.match(/Id$/)){
														var pro = name.substring(0,name.length-2);
														if (entity[pro] &&entity[pro].id){
															$(value).val(entity[pro].id);
					 										$(value).uniform();
				 										}
				 									
													}
													else{
				 										$(value).val("");
													}}
												
											});
											
											var x = $("#productDownloadDiv").find("div.modal-body").find('input[type="radio"]').uniform();
				   							$("#productDownloadDiv input[name='action']").val("${ctx}/admin/product-download/"+id+"/edit/");
				     	    				$("#productDownloadDiv").modal('show');
				 					}
								}
							});		  
				 
					     
					    });
					var recordColumn = ['','name','image','orderRank','date','category','link'];
					
					 $('.productDownloadTable').dataTable({
						"bLengthChange" : true,
						"aoColumnDefs" : [ {
							'bSortable' : false,
							'aTargets' : [0,6 ]
						} ],
				 		"sAjaxSource" : '${ctx}/admin/product-download/${entity.id}/',
						"createQueryData" : function (aoData){
								return	johnny.initQueryData(aoData, recordColumn);
						},
						"createResult" : function (json, echo){
				 			var dataArray = new Array();
							for ( var i = 0; i < json.result.length; i++) {
								var subArray = new Array();
								var value = johnny.getForSelect(json.result[i].id);
								subArray.push(value);
								subArray.push(json.result[i].name)
				subArray.push(json.result[i].image)
				subArray.push(json.result[i].orderRank)
				subArray.push(json.result[i].date)
				subArray.push(json.result[i].attachmentUrl)
				subArray.push(json.result[i].link)

				if (json.result[i].category){
				subArray.push(json.result[i].category.name)
				}else{
				subArray.push("");
				}

					
								
								
								
				   				var conf = [{
									link : 'javascript:void(1)',
									dataId : json.result[i].id,
									text : 'edit',
									css  : 'icomoon-icon-pencil'
								} 
								
								];
								subArray.push(johnny.getGridLink(conf)); 
				  				dataArray.push(subArray);
							}
							return {
								sEcho : echo,
								iTotalRecords : json.totalCount,
								iTotalDisplayRecords : json.totalCount,
								aaData : dataArray
							};
						}		
					});
				   
				   
			   },400);

		   }

	});
	
	
	

	 
	
	
	
	
});


</script>